import requests,pytest
from conftest import *
from utils.utils import *
# 第1条测试用例

logger = get_logger(__name__)

@pytest.mark.parametrize('data',read_yaml(r'C:\Users\20176\Desktop\yuekao\data\add.yaml'))
def test_01(login,data):
    logger.info('test_01 start')
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doAdd'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    datas={
        'platformCode':data['platformCode'],
        'platformName':data['platformName']
    }
    add=requests.post(url=urls,headers=headers1,data=datas)
    add_json=add.json()
    print(add_json)
    logger.info('requests success')
    try:
        # 断言success是否为True
        assert add_json['success'] == True
        # 断言响应时间是否小于2秒
        assert add.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert add.status_code == 200
    except Exception as e:
        print(e)
    logger.info('test_01 end')

# 第2条测试用例
@pytest.mark.parametrize('data',read_json(r'C:\Users\20176\Desktop\yuekao\data\upda.json'))
def test_02(login,data):
    logger.info('test_02 start')
    j_id=login
    urls='http://47.113.229.131:9080/jeewms/baPlatformController.do?doUpdate'
    headers1={
        'content-type':'application/x-www-form-urlencoded',
        'Cookie':f'JSESSIONID={j_id}'
    }
    datas={
        'id':'2c9efaca98b2815401992c2452050c02',
        'platformCode':data['platformCode'],
        'platformName':data['platformName']
    }
    up=requests.post(url=urls,headers=headers1,data=datas)
    up_json=up.json()
    print(up_json)
    logger.info('requests success')
    try:
        # 断言msg是否为月台主数据更新成功
        assert up_json['msg'] == '月台主数据更新成功'
        # 断言响应时间是否小于2秒
        assert up_json.elapsed.total_seconds() <= 2
        # 断言状态码是否为200
        assert up_json.status_code == 200
    except Exception as e:
        print(e)
    logger.info('test_02 end')
